package com.hxs.learn.web;

import com.hxs.learn.common.web.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Spring的ApplicationContext的持有者,可以用静态方法的方式获取spring容器中的bean
 *
 * @author HuXinsheng
 */
@Component
public class SpringContextHolder implements ApplicationContextAware {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (logger.isDebugEnabled()) {
            logger.debug("设置应用上下文...");
        }
        HttpContext.setApplicationContext(applicationContext);
    }

}
